package com.sjd.web.api;

import com.sjd.common.core.domain.AjaxResult;
import com.sjd.common.core.domain.entity.SysDictData;
import com.sjd.common.utils.StringUtils;
import com.sjd.provider.FileOssServerProvider;
import com.sjd.system.service.ISysDictTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 微信用户
 *
 * @author male
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/weixin/api/ma/common")
@Api(value = "wxCommon", tags = "小程序通用API")
public class WxCommonApi {
    private final FileOssServerProvider fileOssServerProvider;
    private final ISysDictTypeService dictTypeService;

    @ApiOperation(value = "小程序oss授权根据provider")
    @GetMapping("/oss/auth/{provider}")
    public AjaxResult ossAuthByProvider(@PathVariable(name = "provider") String provider) {
        return fileOssServerProvider.ossAuthByProvider(provider);
    }

    /**
     * 根据字典类型查询字典数据信息
     */
    @ApiOperation(value = "根据dictType获取字典列表")
    @GetMapping(value = "/dict/{dictType}")
    public AjaxResult dictType(@PathVariable String dictType) {
        List<SysDictData> data = dictTypeService.selectDictDataByType(dictType);
        if (StringUtils.isNull(data)) {
            data = new ArrayList<>();
        }
        return AjaxResult.success(data);
    }
}
